package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.TablePProject;
import com.ruoyi.system.service.ITablePProjectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TablePProjectTask;
import com.ruoyi.system.service.ITablePProjectTaskService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目任务Controller
 * 
 * @author ruoyi
 * @date 2022-05-17
 */
@Controller
@RequestMapping("/system/task")
public class TablePProjectTaskController extends BaseController
{
    private String prefix = "system/task";

    @Autowired
    private ITablePProjectTaskService tablePProjectTaskService;

    @Autowired
    private ITablePProjectService tablePProjectService;

    @RequiresPermissions("system:task:view")
    @GetMapping()
    public String task()
    {
        return prefix + "/task";
    }

    /**
     * 查询项目任务列表
     */
    @RequiresPermissions("system:task:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TablePProjectTask tablePProjectTask)
    {
        startPage();
        List<TablePProjectTask> list = tablePProjectTaskService.selectTablePProjectTaskList(tablePProjectTask);
        return getDataTable(list);
    }

    /**
     * 导出项目任务列表
     */
    @RequiresPermissions("system:task:export")
    @Log(title = "项目任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TablePProjectTask tablePProjectTask)
    {
        List<TablePProjectTask> list = tablePProjectTaskService.selectTablePProjectTaskList(tablePProjectTask);
        ExcelUtil<TablePProjectTask> util = new ExcelUtil<TablePProjectTask>(TablePProjectTask.class);
        return util.exportExcel(list, "项目任务数据");
    }

    /**
     * 新增项目任务
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        TablePProject tablePProject = new TablePProject();
        tablePProject.setTenderStatus(2l);
        List<TablePProject> tablePProjectlist = tablePProjectService.selectTablePProjectList(tablePProject);
        mmap.put("tablePProject", tablePProjectlist);
        return prefix + "/add";
    }

    /**
     * 新增保存项目任务
     */
    @RequiresPermissions("system:task:add")
    @Log(title = "项目任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TablePProjectTask tablePProjectTask)
    {
        return toAjax(tablePProjectTaskService.insertTablePProjectTask(tablePProjectTask));
    }

    /**
     * 修改项目任务
     */
    @RequiresPermissions("system:task:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TablePProjectTask tablePProjectTask = tablePProjectTaskService.selectTablePProjectTaskById(id);
        mmap.put("tablePProjectTask", tablePProjectTask);
        TablePProject tablePProject = new TablePProject();
        tablePProject.setTenderStatus(2l);
        List<TablePProject> tablePProjectlist = tablePProjectService.selectTablePProjectList(tablePProject);
        mmap.put("tablePProject", tablePProjectlist);
        return prefix + "/edit";
    }


    /**
     * 修改项目任务
     */
    @RequiresPermissions("system:task:approve")
    @GetMapping("/approve/{id}")
    public String approve(@PathVariable("id") Long id, ModelMap mmap)
    {
        TablePProjectTask tablePProjectTask = tablePProjectTaskService.selectTablePProjectTaskById(id);
        mmap.put("tablePProjectTask", tablePProjectTask);

        TablePProject tablePProject = new TablePProject();
        tablePProject.setTenderStatus(2l);
        List<TablePProject> tablePProjectlist = tablePProjectService.selectTablePProjectList(tablePProject);
        mmap.put("tablePProject", tablePProjectlist);

        return prefix + "/approve";
    }

    /**
     * 修改保存项目任务
     */
    @RequiresPermissions("system:task:edit")
    @Log(title = "项目任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TablePProjectTask tablePProjectTask)
    {
        return toAjax(tablePProjectTaskService.updateTablePProjectTask(tablePProjectTask));
    }

    /**
     * 审核保存项目任务
     */
    @RequiresPermissions("system:task:approve")
    @Log(title = "项目任务", businessType = BusinessType.UPDATE)
    @PostMapping("/approve")
    @ResponseBody
    public AjaxResult approve(TablePProjectTask tablePProjectTask)
    {
        tablePProjectTask.setApproveTime(new Date());
        return toAjax(tablePProjectTaskService.updateTablePProjectTask(tablePProjectTask));
    }

    /**
     * 删除项目任务
     */
    @RequiresPermissions("system:task:remove")
    @Log(title = "项目任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tablePProjectTaskService.deleteTablePProjectTaskByIds(ids));
    }
}
